//
//  ErrorHistoryTopCell.m
//  GoldOperationClient
//
//  Created by yaxue wang on 2016/11/25.
//  Copyright © 2016年 展鸿科技. All rights reserved.
//

#import "ErrorHistoryTopCell.h"
#import "ErrorHistoryModel.h"

@interface ErrorHistoryTopCell()
@property (nonatomic, strong) UIImageView *headImg;
@property (nonatomic, strong) UIImageView *timeImg;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UILabel *stateLab;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *pollingLab;

@end

@implementation ErrorHistoryTopCell

- (void)initView{
    [super initView];
    self.backgroundColor =[UIColor whiteColor];
    self.line =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, WindowWidth, 0.5)];
    [self addSubview:self.line];
    
    self.line.backgroundColor =C(@"E5E5E5");
    
    self.headImg=[[UIImageView alloc]init];
    [self addSubview:self.headImg];
    [self.headImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        make.centerY.equalTo(self);
    }];
    self.headImg.layer.masksToBounds=YES;
    self.headImg.layer.cornerRadius=25;
    
    self.nameLab = [[UILabel alloc]init];
    [self addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImg.mas_right).offset(15);
        make.top.equalTo(self).offset(20);
        make.right.equalTo(self).offset(-10);
    }];
    self.nameLab.textColor =C(@"009341");
    self.nameLab.font =F(15);
    UIImage *timeImage=[UIImage imageNamed:@"Ico_home_time"];
    self.timeImg=[[UIImageView alloc]init];
    [self addSubview:self.timeImg];
    self.timeImg.image=timeImage;
    [self.timeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLab);
        make.size.mas_equalTo(CGSizeMake(timeImage.size.width, timeImage.size.height));
        make.bottom.equalTo(self.mas_bottom).offset(-12);
    }];
    
    self.timeLab =[[UILabel alloc]init];
    [self addSubview:self.timeLab];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeImg.mas_right).offset(5);
        make.centerY.equalTo(self.timeImg);
        //        make.bottom.equalTo(self.mas_bottom).offset(-12);
    }];
    self.timeLab.font =F(12);
    self.timeLab.textColor =LightFontColor;
    
    self.stateLab = [[UILabel alloc] init];
    [self addSubview:self.stateLab];
    [self.stateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.centerY.equalTo(self.timeImg);
        make.width.equalTo(@(50));
        make.height.equalTo(@(20));
        
    }];
    self.stateLab.textColor =[UIColor whiteColor];
    self.stateLab.layer.masksToBounds=YES;
    self.stateLab.layer.cornerRadius=3;
    self.stateLab.textAlignment=NSTextAlignmentCenter;
    self.stateLab.font =F(10);
    self.pollingLab = [[UILabel alloc]init];
    [self addSubview:self.pollingLab];
    self.pollingLab.text=@"检";
    [self.pollingLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.height.equalTo(@(20));
        make.width.equalTo(@(25));
        make.right.equalTo(self).offset(-16);
    }];
    self.pollingLab.backgroundColor=MainColor;//C(@"1aa3aa");
    self.pollingLab.textColor =[UIColor whiteColor];
    self.pollingLab.font =F(14);
    self.pollingLab.textAlignment=NSTextAlignmentCenter;
    
    [self bk_whenTapped:^{
        if (self.btnBlock) {
            self.btnBlock(self,HomeCellType_Detail,nil);
        }
        
    }];

    
}

- (void)setModel:(id)model
{
    ErrorHistoryModel *order = model;
    self.headImg.image= [UIImage imageNamed:@"Ico_home_bank"];
    self.nameLab.text=order.E_inst_name;
    NSString *timeString = [order.E_created  substringWithRange:NSMakeRange(0, 16)];
    self.timeLab.text=timeString;
    //H_order_type 1 为报修单 2为巡检单
    if ([order.E_order_type isEqualToString:@"1"]) {
        self.pollingLab.hidden=YES;
        if (order.E_state ==nil||[order.E_state isEqualToString:@""])
        {
            
        }else
        {
            NSInteger num=[order.E_state integerValue];
            
            if(num ==97)
            {
                self.stateLab.text =@"已撤销";
                self.stateLab.backgroundColor=C(@"e0e0e0");
                
            }else if (num ==98) {
                
             
                self.stateLab.text =@"待评价";
                self.stateLab.backgroundColor=C(@"e0e0e0");
                
            }else if (num==99)
            {
                self.stateLab.text =@"已完成";
                self.stateLab.backgroundColor=C(@"e0e0e0");
            }

        }
    }else
    {
        self.pollingLab.hidden=NO;
        self.pollingLab.text=@"检";
        if (order.E_state ==nil||[order.E_state isEqualToString:@""])
        {
            
        }else
        {
            NSInteger num=[order.E_state integerValue];

            if(num ==91)
            {
                self.stateLab.text =@"已撤销";
                self.stateLab.backgroundColor=C(@"e0e0e0");
                
            }
            if (num==90) {
                
                self.stateLab.text =@"待评价";
                self.stateLab.backgroundColor=C(@"e0e0e0");
                
                
            }else if (num==90)
            {
                self.stateLab.text =@"已完成";
                self.stateLab.backgroundColor=C(@"e0e0e0");
            }
        }
    }
    
}

@end
